package club.pinea;

import club.pinea.loader.CommandLoader;
import club.pinea.server.GameServer;
import club.pinea.server.LobbyServer;
import club.pinea.server.LoginServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;

@SpringBootApplication(scanBasePackages = {
        "club.pinea.utils",
        "club.pinea.config",
        "club.pinea.server",
        "club.pinea.service",
        "club.pinea.loader",
        "club.pinea",
})
public class GameApplication implements CommandLineRunner {

    @Autowired
    private GameServer gameServer;

    @Autowired
    private LoginServer loginServer;

    @Autowired
    private CommandLoader commandLoader;


    public static void main(String[] args) {
        new SpringApplicationBuilder(GameApplication.class).web(WebApplicationType.NONE).run(args);
    }

    @Override
    public void run(String... args) throws Exception {
        // 依次启动服务器
        new Thread(loginServer).start();
        new Thread(gameServer).start();
        // 加载指令映射
        commandLoader.loadCommand();
    }
}
